﻿Public Class DinstanciaTP

    Public Shared Function SeleccionarTodo(ByVal descEmpresa As String) As List(Of EinstanciasTP)
        Dim InstanciasTP As List(Of EinstanciasTP) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_instanciaTechoPropio_sel", cn)
                cmd.CommandType = CommandType.StoredProcedure
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            InstanciasTP = New List(Of EinstanciasTP)
                            Dim InstanciaTP As EinstanciasTP = Nothing
                            Do While dr.Read
                                InstanciaTP = New EinstanciasTP( _
                                    dr.GetInt32(dr.GetOrdinal("idInstanciaTP")), _
                                    dr.GetString(dr.GetOrdinal("descInstanciaTP")), _
                                    dr.GetString(dr.GetOrdinal("estado")), _
                                    dr.GetString(dr.GetOrdinal("fechaInstanciaTP")), _
                                    dr.GetInt32(dr.GetOrdinal("Orden")), _
                                    dr.GetString(dr.GetOrdinal("descUsuario")))
                                InstanciasTP.Add(InstanciaTP)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return InstanciasTP
    End Function
    Public Shared Function SeleccionarTodoxEstado(ByVal descEmpresa As String) As List(Of EtpoConstruccion)
        Dim tpoConstrucciones As List(Of EtpoConstruccion) = Nothing

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_tpoConstruccion_selxEstado", cn)
                cmd.CommandType = CommandType.StoredProcedure
                Try
                    cn.Open()
                    Using dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult Or CommandBehavior.CloseConnection)
                        If dr.HasRows Then
                            tpoConstrucciones = New List(Of EtpoConstruccion)
                            Dim tpoConstruccion As EtpoConstruccion = Nothing
                            Do While dr.Read
                                tpoConstruccion = New EtpoConstruccion( _
                                    dr.GetInt32(dr.GetOrdinal("idTpoConstruccion")), _
                                    dr.GetString(dr.GetOrdinal("descTpoConstruccion")), _
                                    dr.GetString(dr.GetOrdinal("estado")))
                                tpoConstrucciones.Add(tpoConstruccion)
                            Loop
                            dr.Close()
                        End If
                    End Using
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return tpoConstrucciones
    End Function
    Public Shared Function Añadir(ByVal descEmpresa As String, ByVal pinstanciaTP As EinstanciasTP) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_instanciaTechoPropio_add", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@descInstancia", SqlDbType.VarChar, 55).Value = pinstanciaTP.descInstanciaTP
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = pinstanciaTP.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function
    Public Shared Function Editar(ByVal descEmpresa As String, ByVal pinstanciaTP As EinstanciasTP) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_instanciaTechoPropio_edit", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idInstancia", SqlDbType.Int).Value = pinstanciaTP.idInstanciaTP
                cmd.Parameters.Add("@descInstancia", SqlDbType.VarChar, 55).Value = pinstanciaTP.descInstanciaTP
                cmd.Parameters.Add("@estado", SqlDbType.Char, 1).Value = pinstanciaTP.estado
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = pinstanciaTP.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function
    Public Shared Function Eliminar(ByVal descEmpresa As String, ByVal pinstanciaTP As EinstanciasTP) As Boolean
        Dim resultado As Boolean = False

        Using cn As New SqlConnection(ConfigurationManager.ConnectionStrings(descEmpresa).ConnectionString)
            Using cmd As New SqlCommand("usp_instanciaTechoPropio_del", cn)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.Add("@idinstanciaTP", SqlDbType.Int).Value = pinstanciaTP.idInstanciaTP
                cmd.Parameters.Add("@idUsuario", SqlDbType.Int).Value = pinstanciaTP.idUsuario
                Try
                    cn.Open()
                    cmd.ExecuteNonQuery()
                    resultado = True
                Catch ex As Exception
                    Throw
                End Try
            End Using
        End Using

        Return resultado
    End Function
End Class
